//
//  PKSubcriptionViewController.swift
//  GoAbroad
//
//  Created by Pink Snow on 2025/5/28.
//

import UIKit
import RxSwift
import RxCocoa
import SnapKit
class PKSubcriptionViewController: UIViewController {
  
    let imageView = UIImageView()
    let topButton = UIButton(type: .custom)
    let bottomButton = UIButton(type: .custom)
    let generateButton = UIButton(type: .custom)
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        
        view.addSubview(imageView)
        imageView.isUserInteractionEnabled = true
        imageView.addSubview(generateButton)
        imageView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        imageView.image = .init(named: "cards_5")
        generateButton.snp.makeConstraints { make in
            make.bottom.equalTo(-DeviceHelper.bottomSafeAreaHeight-40)
            make.width.equalTo(140)
            make.height.equalTo(44)
            make.centerX.equalToSuperview()
        }
        [topButton, bottomButton].forEach { button in
                    button.layer.cornerRadius = 8
                    button.layer.borderWidth = 2
                    button.layer.borderColor = UIColor.lightGray.cgColor
                    button.setTitleColor(.white, for: .normal)
                    button.setTitle("测试", for: .normal)
                    button.translatesAutoresizingMaskIntoConstraints = false
                    button.addTarget(self, action: #selector(buttonTapped(_:)), for: .touchUpInside)
            imageView.addSubview(button)
                }
        selectButton(topButton)
        bottomButton.snp.makeConstraints { make in
            make.bottom.equalTo(generateButton.snp.top).offset(-80)
            make.width.equalTo(200)
            make.height.equalTo(44)
            make.centerX.equalToSuperview()
        }
        
        topButton.snp.makeConstraints { make in
            make.bottom.equalTo(bottomButton.snp.top).offset(-20)
            make.width.equalTo(bottomButton)
            make.height.equalTo(bottomButton)
            make.centerX.equalTo(bottomButton)
        }
   
        

        

        generateButton.setTitle("generate", for: .normal)
//        topButton.layer.borderWidth = 1
//        topButton.layer.borderColor = UIColor.green.cgColor
//        bottomButton.layer.borderWidth = 1
//        bottomButton.layer.borderColor = UIColor.green.cgColor
        
        

        
        generateButton.backgroundColor = .systemPink
        generateButton.layer.cornerRadius = 22
        generateButton.clipsToBounds = true
        
        // Do any additional setup after loading the view.
    }
    
    @objc func toggleSelected(_ sender: UIButton) {
        sender.isSelected.toggle()
        
        if sender.isSelected {
            sender.layer.borderWidth = 2
            sender.layer.borderColor = UIColor.systemBlue.cgColor
            sender.transform = CGAffineTransform(scaleX: 1.05, y: 1.05)
        } else {
            sender.layer.borderWidth = 0
            sender.transform = .identity
        }
    }
    @objc func buttonTapped(_ sender: UIButton) {
            selectButton(sender)
        }
    
    func selectButton(_ selected: UIButton) {
          [topButton, bottomButton].forEach { button in
              let isSelected = (button == selected)
              button.layer.borderColor = isSelected ? UIColor.systemBlue.cgColor : UIColor.lightGray.cgColor
          }
      }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
